package org.lagou.filter;

import java.util.*;

/**
 * @author junbao
 */
public class SaveInvokeTime {

    public static SortedMap<Long, Integer> sortedMap = new TreeMap<>();

    public static int getTpTime(int tp) {

        System.out.println("当前map大小：" + sortedMap.size());
        long currentTime = System.currentTimeMillis();
        long countTime = currentTime - 60 * 1000;
        SortedMap<Long, Integer> countMap = sortedMap.tailMap(countTime);
        System.out.println("本次map大小：" + countMap.size());
        System.out.println("本次起始时间：" + countMap.firstKey());
        System.out.println("本次结束时间：" + countMap.lastKey());

        SortedMap<Integer, Integer> countMapTime = new TreeMap<>();
        List<Integer> list = new ArrayList<>();
        for (Map.Entry<Long, Integer> entry: countMap.entrySet()) {
            list.add(entry.getValue());
        }
        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });
        int size = list.size()-1;
        System.out.println("本次最小值：" + list.get(0));
        System.out.println("--------：" + list.get(1));
        System.out.println("--------：" + list.get(2));
        System.out.println("--------：" + list.get(3));
        System.out.println("--------：" + list.get(4));
        System.out.println("本次最大值：" + list.get(size));

        int flag = size * tp / 100 + 1;
        System.out.println("flag值：" + flag);
        // sortedMap = countMap;
        return list.get(flag);

    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(6);
        list.add(4);
        list.add(967);
        list.add(34);
        list.add(345);
        list.add(57);

        list.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });

        for (int i = 0; i < list.size(); i++) {
            Integer integer =  list.get(i);
            System.out.println(integer);

        }


    }

}
